package main

import (
	"flag"
	"fmt"
	"log"
	"redis-push/pkg/config"
	"redis-push/pkg/db"
	"redis-push/pkg/instance"
	"runtime"
)

const Version = "0.0.1"

func main() {
	var configFile string
	var version bool
	var syncdb bool
	flag.StringVar(&configFile, "f", "app.ini", "config file")
	flag.BoolVar(&version, "v", false, "show version")
	flag.BoolVar(&syncdb, "syncdb", false, "migrate tables")
	flag.Parse()
	if version {
		fmt.Printf("%s by %v\n", Version, runtime.Version())
		return
	}
	err := config.LoadConfig(configFile)
	if err != nil {
		panic(err)
	}
	if syncdb {
		fmt.Println(config.NewHandler().SQLiteConfig.ShowSQL)
		op, err := db.NewDB(config.NewHandler().SQLiteConfig.PATH, config.NewHandler().SQLiteConfig.ShowSQL)
		if err != nil {
			panic(err)
		}
		err = op.AutoMigrate(&instance.Instance{})
		if err != nil {
			log.Println(err)
		} else {
			log.Println("同步完成")
		}
		return
	}
	log.Println("end...")
}
